<template>
    <div class="app-container">
  
      <div class="search-div">
        <el-form label-width="80px" size="small">
            <el-row style="display:flex">
                <el-col :span="4">
                    <el-form-item label="试卷名称:">
                        {{ this.$route.query.name }}
                    </el-form-item>
                </el-col>
            </el-row>
          <el-row>
            <el-col :span="4">
              <el-input style="width: 95%" v-model="searchObj.name" placeholder="用户名"></el-input>
            </el-col>
            <el-col :span="8">
              <el-form-item label="做题时间">
                <el-date-picker
                  v-model="createTimes"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="margin-right: 10px;width: 100%;"
                />
              </el-form-item>
            </el-col>

          </el-row>
          <el-row style="display:flex">
            <el-button type="primary" icon="el-icon-search" size="mini"  @click="fetchData()">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button>
          </el-row>
        </el-form>
      </div>
  
  
      <!-- 列表 -->
      <el-table
        v-loading="listLoading"
        :data="list"
        stripe
        border
        style="width: 100%;margin-top: 10px;">
        <el-table-column
          label="序号"
          width="50"
          align="center">
          <template slot-scope="scope">
            {{ (page - 1) * limit + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="username" label="用户名"/>
        <el-table-column prop="name" label="用户"/>
        <el-table-column prop="point" label="得分"/>
        <el-table-column prop="createTime" label="做题时间" />
        <el-table-column label="操作"  align="center" fixed="right" width="150">
          <template slot-scope="scope">
            <el-button type="danger" plain round icon="el-icon-check" size="mini" @click="Correcting(scope.row)" title="批改"/>
            <el-button type="warning" plain round :icon="reFreshIcon" :disabled="reFreshDisabled" size="mini" @click="reFresh(scope.row.id)" title="刷新成绩" />
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        style="padding: 30px 0; text-align: center;"
        layout="total, prev, pager, next, jumper"
        @current-change="fetchData"
      />
    </div>
  </template>
  <style>
      .search-div {
          padding:10px;border: 1px solid #EBEEF5;border-radius:3px;
      }
      .tools-div {
          margin-top: 10px;padding:10px;border: 1px solid #EBEEF5;border-radius:3px;
      }
  </style>
  <script>
  import api from '@/api/El/eluserPaper'
  const defaultForm = {
    id: '',
    username:'',
    name: '',
    point:'',
  }
  export default {
    data() {
      return {
        reFreshIcon:'el-icon-refresh-right', //刷新图标展示
        reFreshDisabled : false,    //刷新是否可以点击
        listLoading: true, // 数据是否正在加载
        list: null, // banner列表
        total: 0, // 数据库中的总记录数
        page: 1, // 默认页码
        limit: 10, // 每页记录数
        searchObj: {    //条件查询
          name:''
        },
  
        createTimes: [],
  
        checkAll: false, // 是否全选
  
        dialogVisible: false,
        WorkDetail: defaultForm,

      }
    },
    // 生命周期函数：内存准备完毕，页面渲染成功
    mounted() {
      this.fetchData()
    },
  
    methods: {
      
      // 加载banner列表数据
      fetchData(page = 1) {
        this.page = page
        if(this.createTimes && this.createTimes.length ==2) {
          this.searchObj.createTimeBegin = this.createTimes[0]
          this.searchObj.createTimeEnd = this.createTimes[1]
        }
        
        api.workDetail(this.page, this.limit,this.$route.query.id, this.searchObj).then(
          response => {
            this.list = response.data.records
            this.total = response.data.total
            // 数据加载并绑定成功
            this.listLoading = false
          }
        )
  
      },
      //刷新信息
      reFresh(id){
          this.reFreshIcon = "el-icon-loading"
          this.reFreshDisabled = true
          api.UpdatePoint(id).then(resp => {
              this.$message.success('刷新成功')
              this.reFreshIcon = "el-icon-refresh-right"
              this.reFreshDisabled = false
              this.fetchData(this.page)
          })
      },
  
      // 重置查询表单
      resetData() {
        this.searchObj = {}
        this.createTimes = []
        this.fetchData()
      },

        //批改作业
        Correcting(row){
          this.$router.push('/work/Correcting?id='+row.id+'&name='+row.name);
        },
    }
  }
  </script>